import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/goods/detail/view.dart';
import 'package:flutter_jd/pages/tabbar/home/controller.dart';
import 'package:flutter_jd/tools/data/mock.dart';
import 'package:flutter_jd/tools/utils/utils.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/route_manager.dart';

// 秒杀
class Seckill extends GetWidget<HomeController> {
  @override
  Widget build(BuildContext context) {
    return _buildSeckill();
  }

  // 秒杀
  _buildSeckill() {
    return Container(
      margin: EdgeInsets.only(left: 10.w, right: 10.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.r),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(left: 10.w, top: 8.h),
            child: Row(
              children: [
                Text(
                  '京东秒杀',
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w),
                  child: Text(
                    '20',
                    style: TextStyle(
                      color: Utils.hexToColor('#FB341F'),
                      fontSize: 14.sp,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
                Container(
                  width: 22.sp,
                  child: Image.asset(
                    'assets/images/home/ms.png',
                    fit: BoxFit.cover,
                  ),
                ),
                Row(
                  children: [
                    _buildCountDown('00', 10),
                    _buildListCardSplit(),
                    _buildCountDown('08', 0),
                    _buildListCardSplit(),
                    _buildCountDown('12', 0)
                  ],
                ),
              ],
            ),
          ),
          Container(
            height: 195,
            padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
            child: GridView.count(
              padding: EdgeInsets.all(0),
              crossAxisCount: 4,
              crossAxisSpacing: 10,
              mainAxisSpacing: 10,
              physics: NeverScrollableScrollPhysics(),
              children: List.generate(
                PRODUCT_LIST.length,
                (index) => Container(
                  child: GestureDetector(
                    onTap: () {
                      Get.to(
                        () => GoodsDetail(arguments: {
                          'imgUrl': controller.goodsList[index]['src'],
                          'name': controller.goodsList[index]['name'],
                          'price': controller.goodsList[index]['price'],
                        }),
                      );
                    },
                    child: Image.asset(PRODUCT_LIST[index]['src']),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  _buildCountDown(String time, double left) {
    return Container(
      width: 17.sp,
      height: 17.sp,
      alignment: Alignment.center,
      margin: EdgeInsets.only(left: left),
      decoration: BoxDecoration(
        color: Utils.hexToColor('#FB4321'),
        borderRadius: BorderRadius.circular(4.r),
      ),
      child: Text(
        time,
        style: TextStyle(
          color: Colors.white,
          fontSize: 10.sp,
          fontWeight: FontWeight.w500,
        ),
      ),
    );
  }

  _buildListCardSplit() {
    return Container(
      padding: EdgeInsets.all(3.w),
      child: Text(
        ':',
        style: TextStyle(
          color: Utils.hexToColor('#FB4321'),
          fontSize: 12.sp,
          fontWeight: FontWeight.w600,
        ),
      ),
    );
  }
}
